// pages/index/discussion/discussion.js
import Dialog from "../../../miniprogram_npm/@vant/weapp/dialog/dialog"
import Toast from "../../../miniprogram_npm/@vant/weapp/toast/toast"

const app = getApp()
const log = new app.appLogs()
const http = new app.appHttp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        active: 1,
        page_number: 1,
        ConductList: [],
        FinishedList: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            theme: app.globalData.theme
        })
        this.getConductList()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    /**
     * 切换标签
     * @param event
     */
    onChange(event) {
        log.e(JSON.stringify(event))
        const than = this
        if (event.detail.index == 0) {
            than.getConductList()
        } else if (event.detail.index == 1) {
            than.getFinishedList()
        }
    },
    /**
     * 获取进行中
     * @param e
     */
    getConductList: function (e) {
        const than = this
        http.get("bouleuterion/pagination", {
            area_code: app.globalData.areaCode,
            page_number: 1,
            page_size: 100,
            status: 1
        }).then(res => {
            if (res.data.code == 200) {
                than.setData({
                    ConductList: res.data.data.list
                })
            }
        })
    },
    /**
     * 获取已结束
     * @param e
     */
    getFinishedList: function (e) {
        const than = this
        http.get("bouleuterion/pagination", {
            area_code: app.globalData.areaCode,
            page_number: 1,
            page_size: 100,
            status: 0
        }).then(res => {
            if (res.data.code == 200) {
                than.setData({
                    FinishedList: res.data.data.list
                })
            }
        })
    },
    onDetails: function (e) {
        const id = e.currentTarget.dataset.id
        wx.navigateTo({
            url: '../discussion/discussiondetails/discussiondetails?id=' + id 
        })
    }
})